package com.simu.towercrane.fragments;


import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.simu.towercrane.R;
import com.simu.towercrane.adapter.GlassespagerAdapter;

public class GlassesFragment extends BaseFragment{

	 private ViewPager viewPager;
	    private GlassespagerAdapter myGlassespagerAdapter;

	    private TextView Tvershou;
	    private TextView Tverzhixun;
	    private TextView TvShangjia;
	    @Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			return inflater.inflate(R.layout.fragment_glasses, container, false);
		}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		// TODO Auto-generated method stub
		 Tvershou = (TextView) getView().findViewById (R.id.glassetextView1);
	     Tverzhixun = (TextView) getView().findViewById (R.id.glassetextView2);
	     TvShangjia = (TextView) getView().findViewById(R.id.glassetextView3);
	    
			FragmentErShou one=new FragmentErShou();
			FragmentZhiXun two=new FragmentZhiXun();
			FragmentShangJia three = new FragmentShangJia();
			
			ArrayList<Fragment> lists=new ArrayList<Fragment>();
			lists.add(one);
			lists.add(two);
			lists.add(three);
			myGlassespagerAdapter=new GlassespagerAdapter(getFragmentManager(),lists);
//			ViewPager viewPager=(ViewPager) findViewById(R.id.viewpager);
//			//viewPager.setCurrentItem(item);		
//			viewPager.setAdapter(customFragmentPageAdapter);
//			
//			
//			
//	     lists.add(getLayoutInflater().findViewById(R.layout.fragment_glasses_ershou));
//	     lists.add(getLayoutInflater().findViewById(R.layout.fragment_glasses_zhixun));
//	        myGlassespagerAdapter=new GlassespagerAdapter(lists);
	        
	        viewPager = (ViewPager)getView().findViewById(R.id.viewPager);
	        viewPager.setAdapter(myGlassespagerAdapter);
	        Tvershou.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					Tvershou.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
					// TODO Auto-generated method stub
					Tverzhixun.setTextColor(getResources().getColor(R.color.normal_text_color));
					TvShangjia.setTextColor(getResources().getColor(R.color.normal_text_color));
					viewPager.setCurrentItem(0);
				}
			});
	        Tverzhixun.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Tverzhixun.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
					// TODO Auto-generated method stub
					Tvershou.setTextColor(getResources().getColor(R.color.normal_text_color));
					TvShangjia.setTextColor(getResources().getColor(R.color.normal_text_color));
					viewPager.setCurrentItem(1);
				}
			});
	        TvShangjia.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					Tverzhixun.setTextColor(getResources().getColor(R.color.normal_text_color));
					// TODO Auto-generated method stub
					Tvershou.setTextColor(getResources().getColor(R.color.normal_text_color));
					TvShangjia.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
					viewPager.setCurrentItem(2);
					
				}
			});
	        viewPager.setOnPageChangeListener(new OnPageChangeListener() {
	        	
	       
				
				@Override
				public void onPageSelected(int arg0) {
					// TODO Auto-generated method stub
					switch(arg0)
					{
					case 0:
						Tvershou.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
						Tverzhixun.setTextColor(getResources().getColor(R.color.normal_text_color));
						TvShangjia.setTextColor(getResources().getColor(R.color.normal_text_color));
						break;
					case 1:
						Tverzhixun.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
						Tvershou.setTextColor(getResources().getColor(R.color.normal_text_color));
						TvShangjia.setTextColor(getResources().getColor(R.color.normal_text_color));
						break;
					case 2:
						Tverzhixun.setTextColor(getResources().getColor(R.color.normal_text_color));
						Tvershou.setTextColor(getResources().getColor(R.color.normal_text_color));
						TvShangjia.setTextColor(getResources().getColor(R.color.top_bar_normal_bg));
						break;
					
					}
					
				}
				
				@Override
				public void onPageScrolled(int arg0, float arg1, int arg2) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void onPageScrollStateChanged(int arg0) {
					// TODO Auto-generated method stub
					
				}
			});
	        
	
	}



	
    
}
